Page({
  data: {
    flash: "torch",
    popup: false,
    circle:""
  },
  onLoad() {
    this.ctx = wx.createCameraContext()
  },
  takePhoto() {
    this.ctx.takePhoto({
      quality: 'high',
      success: (res) => {
        this.setData({
          src: res.tempImagePath
        })
      }
    })
    if (this.data.flash === "torch") {
      this.setData({ flash: "off" })
      var that = this
      setTimeout(function () { that.setData({ flash: "torch" }) }, 200);
    }
  },
  changeFlash() {
    if (this.data.flash === "torch") {
      this.setData({ flash: "off" })
    } else {
      this.setData({ flash: "torch" })
    }
    console.log(this.data.flash)
  },
  changecircle(){
    this.setData({popup:true})
  },
  returnBack(event) {
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.emit('returnEvent', {
      src: this.data.src,
    });
    wx.navigateBack({
      delta: 1,
    })
  },
  error(e) {
    console.log(e.detail)
  },
  tosmall(){
    this.setData({circle: "small"})
  },
  tomiddle(){
    this.setData({circle: "middle"})
  },
  tobig(){
    this.setData({circle: "big"})
  }
})
